package cate.common.table;

import easy.java.dev.note.NoteClass;
import easy.java.dev.note.NoteField;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Slf4j
@NoteClass("原始Sheet类")
public class ESheetRaw implements Serializable {
    @Getter
    @Setter
    @NoteField("位置信息")
    private String location;
    @Getter
    @Setter
    @NoteField("列数据信息")
    private List<Map<String, String>> rowValues;

    public List<XSSFRawRowWrap> buildXRWs() {
        try {
            if (rowValues != null) {
                List<XSSFRawRowWrap> ret = new ArrayList<>(rowValues.size());
                rowValues.forEach(fieldToValue -> {
                    if (fieldToValue != null) {
                        XSSFRawRowWrap xrw = new XSSFRawRowWrap(fieldToValue);
                        xrw.setSheetName(location);
                        ret.add(xrw);
                    }
                });
                return ret;
            }
        } catch (Exception e) {
            log.error("[ESheetRaw] build fail!", e);
        }
        return new ArrayList<>();
    }
}
